package com.example.aircraftticketingsystemserver.controller;

import com.example.aircraftticketingsystemserver.entity.Ticket;
import com.example.aircraftticketingsystemserver.service.IFlightsService;
import com.example.aircraftticketingsystemserver.service.ITicketService;
import com.example.aircraftticketingsystemserver.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lxz
 * @since 2024-08-19
 */
@RestController
@CrossOrigin(origins = {"*","null"})
@RequestMapping("/ticket")
public class TicketController {
    @Resource
    private ITicketService ticketService;

    @PostMapping("/addTicket")
    public Result addTicket(@RequestBody Ticket ticket){
        ticketService.addTicket(ticket);
        return Result.ok();
    }
    @PostMapping("/updateTicket")
    public Result updateTicket(@RequestBody Ticket ticket){
        ticketService.updateTicket(ticket);
        return Result.ok();
    }

    @GetMapping("/selectTicketByFlightId")
    public Result selectTicketByFlightId(@RequestParam("flightId") Integer flightId){
        List<Ticket> tickets = ticketService.selectTicketByFlightId(flightId);
        return Result.ok(tickets);
    }

    @GetMapping("/deleteTicketByTicketId")
    public Result deleteTicketByTicketId(@RequestParam("ticketId") Integer ticketId){
        ticketService.deleteTicketByTicketId(ticketId);
        return Result.ok();
    }
}
